// import SMERouter from 'sme-router'

// const router = new SMERouter('router-view')

// router.route('/', (req, res, next) => {
//   const { params, query, body , url, route } = req

//   console.log(params.id) // output => 123
//   console.log(query.name) // output => hwen
//   console.log(body.mes) // output => hallo world
//   console.log(url) // output => /user/123?name=hwen
//   console.log(route) // output => /user/:id

//   res.render(pugTemplate(req))
// })

// router.go('/user/123?name=hwen', { mes: 'hallo world'})

// router.route('*', (req, res, next) => {
//   res.redirect('/index')
// })

// import SMERouter from 'sme-router'
import SMERouter from 'gp21-router'

import index from '../controllers/index'
import listUser from '../controllers/users/list-user'
import listPosition from '../controllers/positions/list-position'
import {signin} from '../controllers/signin'

import {routerGuard as rgModel} from '../models/router-guard'

const router = new SMERouter('router-view');
// console.log(indexTpl)

// console.log(html)

// $('#root').html(html)
// const num = 100
// console.log(num)

router.use(async (req) => {
  let result = await rgModel()
  if(result.ret) {
    // router.go('/index')
    router.go(req.url)
  } else {
    router.go('/signin')
  }
})

// router.route('/', () => {})

router.route('/signin', signin(router))

router.route('/index', index(router))
router.route('/index/users', listUser(router))
router.route('/index/positions', listPosition(router))
router.route('*', (req, res, next) => {
  // console.log('*')
  res.redirect('/index/users')
})

// router.route('/signin', signin(router))

export default router
